package cn.com.nes.site.controller.crm.opportunity;

import cn.com.nes.common.web.CommonResult;
import cn.com.nes.site.controller.crm.opportunity.vo.OpportunityStaffDeleteVO;
import cn.com.nes.site.controller.crm.opportunity.vo.OpportunityStaffPageVO;
import cn.com.nes.site.controller.crm.opportunity.vo.OpportunityStaffSaveVO;
import cn.com.nes.site.service.crm.opportunity.OpportunityStaffService;
import cn.com.nes.site.service.crm.opportunity.bo.OpportunityStaffBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = {"销售管理-商机管理-联系人管理"})
@Controller
@RequestMapping("/v2/crm/opportunity/staff")
public class OpportunityStaffController {

    @Resource
    private OpportunityStaffService opportunityStaffService;

    @ApiOperation(value = "保存商机联系人", notes = "商机详情页-联系人tab")
    @RequestMapping(value = "saveStaff", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> saveStaff(@RequestBody @Validated OpportunityStaffSaveVO vo) throws Exception {
        return CommonResult.data(opportunityStaffService.saveStaff(vo.convertToBo(OpportunityStaffBO.class)));
    }

    @ApiOperation(value = "查询商机联系人分页", notes = "商机详情页-联系人tab")
    @RequestMapping(value = "getStaffPage", method = RequestMethod.GET)
    public @ResponseBody CommonResult<?> getStaffPage(@Validated OpportunityStaffPageVO vo) throws Exception {
        return CommonResult.page(opportunityStaffService.getStaffPage(vo.convertToBo(OpportunityStaffBO.class)));
    }

    @ApiOperation(value = "删除商机联系人", notes = "商机详情页-联系人tab")
    @RequestMapping(value = "deleteStaff", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> deleteStaff(@RequestBody @Validated OpportunityStaffDeleteVO vo) throws Exception {
        opportunityStaffService.deleteStaff(vo.convertToBo(OpportunityStaffBO.class));
        return CommonResult.ok();
    }


}
